package common;

import utils.PropertyUtil;

public class Invoice {

	
	public synchronized static String fetchInvoice() throws Exception{
		String invoice=PropertyUtil.getProperties("invoice.properties").get("invoice").toString();
		Long number=new Long(invoice);
		String newInvoice=String.format("%06d", number.intValue()+1);
		PropertyUtil.setProperties("invoice.properties", new String[]{"invoice"}, new String[]{newInvoice});
		if(invoice.length()>6){
			throw new Exception("Invoice Exception");
		}
		return invoice;
	}
	
	public synchronized static void finishInvoice(){
		PropertyUtil.setProperties("invoice.properties", new String[]{"invoice"}, new String[]{"999999"});
	}
	
}
